@extends('layouts.app')
@section('content')
    <div class="container">
        <div class="row">
            <div class="col-md-12 col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">订单详情</div>
                    <div class="panel-body ">
                        <form action="{{route('admin.order.checkout')}}" method="post" class="form-horizontal">
                            <input type="hidden" name="order_id" value="{{$order->id}}">
                            {{csrf_field()}}
                            <div class="form-group">
                                <label for="email" class="col-md-4 control-label">订单编号</label>
                                <div class="col-md-6">
                                    {{$order->code}} <span class="label label-info">{{$order->status_text}}</span>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <label for="email" class="col-md-4 control-label">日期</label>
                                <div class="col-md-6">
                                    {{$order->created_at}}
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="email" class="col-md-4 control-label">姓名</label>
                                <div class="col-md-6">
                                    {{$order->name}}
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="email" class="col-md-4 control-label">联系电话</label>
                                <div class="col-md-6">
                                    {{$order->phone}}
                                </div>
                            </div>

                            <div class="form-group ">
                                <label for="email" class="col-md-4 control-label">行程</label>
                                <div class="col-md-6">
                                    {{$order->start}}=>{{$order->end}}<br />
                                    出发地：{{$order->start_address}}<br />
                                    目的地：{{$order->end_address}}<br />
                                </div>
                            </div>
                            <div class="form-group ">
                                <label for="email" class="col-md-4 control-label">乘车时间</label>
                                <div class="col-md-6">
                                    {{$order->date}}
                                </div>
                            </div>
                            <div class="form-group ">
                                <label for="email" class="col-md-4 control-label">状态</label>
                                <div class="col-md-6">
                                    {{$order->status_text}}
                                </div>
                            </div>
                            @if($order->status==0)
                            <div class="form-group {{ $errors->has('driver_id') ? ' has-error' : '' }}">
                                <label  class="col-md-4 control-label">选择司机</label>
                                <div class="col-md-6">
                                    <select name="driver_id" size="8" class="form-control" onchange="onChangeLine()">
                                        @foreach($driver_list as $driver)
                                        <option value="{{$driver->id}}" data-price="{{$driver->line->price}}">
                                            {{$driver->trip_text}}(剩余：{{$driver->free}},票价：{{$driver->line->price}}，司机：{{$driver->name}})
                                            {{$driver->return_trip_title}}
                                        </option>
                                        @endforeach
                                    </select>
                                    @if ($errors->has('driver_id'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('driver_id') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group {{ $errors->has('amount') ? ' has-error' : '' }}">
                                <label  class="col-md-4 control-label">金额</label>
                                <div class="col-md-6">
                                    <input type="number" class="form-control" name="amount" >
                                    @if ($errors->has('amount'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('amount') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            <div class="form-group {{ $errors->has('dispatch_at') ? ' has-error' : '' }}">
                                <label  class="col-md-4 control-label">发车时间</label>
                                <div class="col-md-6">                                    
                                    <input class="form-control" type="datetime-local" name="dispatch_at" value="{{date('Y-m-d\TH:i',strtotime($order->date))}}" placeholder="">
                                    @if ($errors->has('dispatch_at'))
                                    <span class="help-block">
                                        <strong>{{ $errors->first('dispatch_at') }}</strong>
                                    </span>
                                    @endif
                                </div>
                            </div>
                            @endif
                            @if(in_array($order->status,[1,2,3]))
                            <div class="form-group">
                                <label  class="col-md-4 control-label">司机</label>
                                <div class="col-md-6">
                                    {{$order->driver->trip_text}}(剩余：{{$order->driver->free}},票价：{{$order->driver->line->price}}，司机：{{$order->driver->name}})
                                            {{$order->driver->return_trip_title}}
                                </div>
                            </div>
                            <div class="form-group {{ $errors->has('amount') ? ' has-error' : '' }}">
                                <label  class="col-md-4 control-label">金额</label>
                                <div class="col-md-6">
                                    {{$order->amount}}
                                </div>
                            </div>
                            <div class="form-group {{ $errors->has('amount') ? ' has-error' : '' }}">
                                <label  class="col-md-4 control-label">发车时间</label>
                                <div class="col-md-6">
                                    {{$order->dispatch_at}}
                                </div>
                            </div>
                            @endif
                            <div class="form-group">
                                <div class="col-md-8 col-md-offset-4">
                                    @if($order->status==0)
                                    <button type="submit" class="btn btn-primary">&nbsp;&nbsp;出票&nbsp;&nbsp;</button>
                                    &nbsp;&nbsp;<a href="{{route('admin.order.fail_checkout',['order_id'=>$order->id])}}">无法出票</a>&nbsp;&nbsp;
                                    @endif
                                    <button type="button" onclick="location.href='{{route('admin.order')}}'" class="btn btn-default">
                                            &nbsp;&nbsp;返回&nbsp;&nbsp;
                                    </button>
                                    <a href="javascript:;" onclick="showMap()">显示/隐藏地图</a>
                                </div>
                            </div>
                            
                            <div class="form-group">
                                <div class="col-md-8 col-md-offset-4">
                                    
                                </div>
                            </div>
                            <div id="map" class="form-group " >
                                <!-- <label for="email" class="col-md-4 control-label">订单明细</label> -->
                                <div class="col-md-12">
                                    <iframe style="width: 100%;height: 700px" id="external-frame" src="http://apis.map.qq.com/uri/v1/routeplan?type=drive&from={{$order->start}}&fromcoord={{$order->start_lat}},{{$order->start_lng}}&to={{$order->end}}&tocoord={{$order->end_lat}},{{$order->end_lng}}&policy=1&referer=myapp" frameborder="0"></iframe>
                                </div>
                            </div>
                            
                            
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
@section('js')
<script>
var mapShowed = true;
function showMap() {
    if(!mapShowed)
        $('#map').show();
    else
        $('#map').hide();
    mapShowed = !mapShowed;
}
$(function(){
    updateAmount();
});

function onChangeLine() {
    updateAmount();
}

function updateAmount() {
    var price = $('select[name="driver_id"] option:selected').attr('data-price');
    $('input[name="amount"]').val(price);
}



</script>
@endsection

